<template>
  <div class="container">
    商品名称：
    <el-input class="com-input" placeholder="请输入内容" v-model="goodsRecheckParams.name"></el-input>
    修改人：
    <el-select v-model="goodsRecheckParams.operatorId" placeholder="全部">
      <el-option
        v-for="item in users"
        :key="item.id"
        :label="item.name"
        :value="item.id"
      ></el-option>
    </el-select>
    状态：
    <el-select v-model="goodsRecheckParams.status" placeholder="全部">
      <el-option
        v-for="item in checkStatus"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      ></el-option>
    </el-select>
    <el-button type="primary" icon="el-icon-search" class="btn" @click="search">查询</el-button>
    <el-main>
      <el-table :data="goodsInfoList">
        <el-table-column prop="id" align="center" label="ID"></el-table-column>
        <el-table-column prop="name" align="center" label="商品名称"></el-table-column>
        <el-table-column prop="ptGoodsPlanName" align="center" label="所属计划"></el-table-column>
        <el-table-column prop="operatorName" align="center" label="修改人"></el-table-column>
        <el-table-column prop="updateTimeValue" align="center" label="修改时间"></el-table-column>
        <el-table-column prop="reason" align="center" label="修改原因"></el-table-column>
        <el-table-column prop="operatorType" align="center" label="类型"></el-table-column>
        <el-table-column prop="status" align="center" label="状态"></el-table-column>
        <el-table-column label="操作" align="center" width="220">
          <template slot-scope="scope">
            <el-button @click="checkDetail(scope.row)" type="text" size="small">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="demonstration-box">
        <!-- <span class="demonstration">显示总数</span> -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageParams.size"
          layout="total, prev, pager, next"
          :total="pageParams.totalCount"
        ></el-pagination>
      </div>
    </el-main>
  </div>
</template>

<script>
const queryString = require('querystring')
import page from 'data/page'
import { getUsers } from 'data/listBody'
import { checkStatus, goodsRecheckParams } from 'data/recheck'
export default {
  name: "goodsList",
  mixins: [page],
  data() {
    return {
      currentPage: 1,
      goodsRecheckParams,
      checkStatus,
      pageShow: false,
      users:[],
      goodsInfoList: []
    };
  },
  props: {
      status: {
        default: false,
        type: Boolean
      }
    },
    created() {
      this.dataInit();
    },
    watch: {
      status(val) {
        if (val) this.search()
      }
    },
  methods: {
    dataInit(){
      getUsers((res)=>{
        this.users = res;
      })
    },
    search() {
      this.goodsRecheckParams.page = this.currentPage - 1
      this.axios.get('/goods/tempList?' + queryString.stringify(this.goodsRecheckParams)).then((res) => {
        const code = Number(res.data.code)
        if (code === 200) {
            this.goodsInfoList = res.data.data.list
            this.goodsInfoList.forEach((goodsInfo, index) => {
              this.goodsInfoList[index].updateTimeValue = this.timeFormater(goodsInfo.updateTime).format('YYYY-MM-DD')
              this.goodsInfoList[index].status = this.getStatusValue(goodsInfo.status)
            })
            this.setPage(res.data.data)
            // if (this.goodsInfoList.length === 0) this.$message(this.mes.noData)
        } else {
            this.$message(this.mes.busy)
        }
      }).catch((err) => {
        console.log(err)
        this.$message(this.mes.busy)
      })
    },
    checkDetail(item) {
      this.$router.push('serveInfo?id=' + item.id + '&operatorType=' + item.operatorType)
    },
    checkDetail(item) {
      this.$router.push('goodsInfo?id=' + item.id)
    },
    getStatusValue(val) {
      let value = ''
      val = String(val)
      switch (val) {
        case '-1': value = '待审核'; break;
        case '0': value = '已审核'; break;
        case '-2': value = '已拒绝'; break;
      }
      return value
    }
  }
};
</script>

<style lang="less" scoped>
@import url('../../../../assets/less/checklist.less');
</style>